// JavaScript Document
$(function(){
	$("#pages_list").change(function(){
		var val = $(this).val();
		if(val!=''){
			getContent(val);
		}
	});
	
	CKEDITOR.replace( 'editor1',
	{
		/*filebrowserBrowseUrl : '/ckfinder/ckfinder.html',
		filebrowserImageBrowseUrl : '/ckfinder/ckfinder.html?type=Images',
		filebrowserFlashBrowseUrl : '/ckfinder/ckfinder.html?type=Flash',
		filebrowserUploadUrl : 
		   '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files&currentFolder=/archive/',
		filebrowserImageUploadUrl : 
		   '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images&currentFolder=/cars/',
		filebrowserFlashUploadUrl : '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Flash'*/
		filebrowserBrowseUrl: '../js/kcfinder/browse.php?type=files',
   		filebrowserImageBrowseUrl: '../js/kcfinder/browse.php?type=images',
  		filebrowserFlashBrowseUrl: '../js/kcfinder/browse.php?type=flash',
   		filebrowserUploadUrl: '../js/kcfinder/upload.php?type=files',
   		filebrowserImageUploadUrl: '../js/kcfinder/upload.php?type=images',
   		filebrowserFlashUploadUrl: '../js/kcfinder/upload.php?type=flash'
	});
	
	//FORM SUBMIT
	$("#ContentManageForm").submit(function(){
		if($("#pages_list").val()!=''){
			return true;
		}else{
			return false;
		}
	});
	
});

function getContent(page_id){
	$.ajax({
			type: "GET",
			url: "getContent/"+page_id,
			data: { page_id: page_id },
			//dataType: 'json',
			success: function(data){
					CKEDITOR.instances.editor1.setData( data);
			},
			error: function(data){
					console.log(data.error.code); // Returns a 403 in debug.
			}
	});
	return false;
}